package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * @author OZ.L.XO
 * #Description OrderMapper
 * #Date: 2025/7/11 19:44
 */
@Mapper
public interface OrderMapper {

    /**
     * 插入订单数据
     * @param order 订单对象
     */
    void insert(Orders order);

    /**
    * @Description
    * @Param [orderNumber, userId]
    * @Date 2025/8/1 22:54
    **/
    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    /**
     * 修改订单信息
     */
    void update(Orders orders);

    /**
    * @Description 修改订单状态
    * @Param [orderStatus, orderPaidStatus, check_out_time, id]
    * @Date 2025/7/31 23:24
    **/
    @Update("update orders set status = #{orderStatus},pay_status = #{orderPaidStatus} ,checkout_time = #{check_out_time} where id = #{id}")
    void updateStatus(Integer orderStatus, Integer orderPaidStatus, LocalDateTime check_out_time, Long id);

    /**
    * @Description 获取所有订单信息
    * @Param [ordersPageQueryDTO]
    * @Date 2025/7/31 23:24
    **/
    Page<Orders> listOrders(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
    * @Description 根据订单id查询订单信息
    * @Param [orderId]
    * @Date 2025/7/31 23:24
    **/
    @Select("select * from orders where id = #{orderId}")
    Orders getByOrderId(Long orderId);

    /**
    * @Description 统计订单数量
    * @Param [confirmed]
    * @Date 2025/7/31 23:24
    **/
    @Select("select count(id) from orders where status = #{status}")
    Integer countStatus(Integer status);

    /**
    * @Description 订单搜索分页查询
    * @Param [ordersPageQueryDTO]
    * @Date 2025/7/31 23:24
    **/
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
    * @Description 处理超时订单
    * @Param [orderId]
    * @Date 2025/7/31 23:24
    **/
    @Select("select * from orders where status = #{status} and order_time < #{time}")
    List<Orders> getByStatusAndOrderTimeOut(Integer status, LocalDateTime time);

    /**
    * @Description 统计营业额数据
    * @Param [map]
    * @Date 2025/7/31 23:24
    **/
    Double sumByMap(Map<String, Object> map);

    /**
    * @Description 统计订单总数
    * @Param [map]
    * @Date 2025/7/31 23:24
    **/
    Integer totalOrder(Map<String, Object> map);

}
